<template>
	<view class="content">
		<u-navbar back-text="" title="">
			<view style="width: 100%;display: flex;justify-content: center;font-weight: bold;font-size: 34rpx;margin-left: 25rpx;">
				申请记录
			</view>
			<view slot="right">
				<view style="margin-right: 35rpx;color: #7a7a7a;">
					
				</view>
			</view>
		</u-navbar>
		<view style="display: flex;flex-direction: column;width: 100%;flex: 1;overflow-y: auto;">
			<view @click="handleApply(item)" v-for="(item,k) in list"
				style="width: 100%;display: flex;align-items: center;justify-content: space-between;padding: 20rpx;border-bottom: 1rpx solid #f4f4f4;">
				<view style="display: flex;align-items: center;">
					<u-avatar :src="$store.state.common.systemInfo.fileurl + 'avatar/' + item.fromid + '.jpg'"></u-avatar>
					<view style="display: flex;flex-direction: column;margin-left: 10rpx;">
						<view style="font-size: 32rpx;font-weight: 500;">
							{{item.fromname}}
						</view>
						<view style="color: #cacaca;">
							{{item.message}}
						</view>
					</view>
				</view>
				<view style="display: flex;flex-direction: column;justify-content: flex-end;">
					<view v-if="item.status == '申请中'" style="color: #ffaa00;display: flex;justify-content: flex-end;">
						申请中
					</view>
					<view v-if="item.status == '已通过'" style="color: #00aa7f;display: flex;justify-content: flex-end;">
						已通过
					</view>
					<view v-if="item.status == '已拒绝'" style="color: #ff557f;display: flex;justify-content: flex-end;">
						已拒绝
					</view>
					<view style="display: flex;justify-content: flex-end;color: #9c9c9c;font-size: 24rpx;">
						{{$u.timeFormat(item.time, 'mm-dd hh:MM:ss')}}
					</view>
				</view>
			</view>
		</view>
		
		<u-action-sheet @click="applyres" :list="hdlist" v-model="show"></u-action-sheet>
	</view>
</template>

<script>
	import moment from 'moment'
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				current: 0,
				show:false,
				hdlist:[{text:'通过'},{text:'拒绝'}],
				currentdata:{},
				id:''
			}
		},
		onLoad({id}) {
			this.id = id
			this.$store.dispatch({
				type:"apply/init",
				payload:{}
			})
		},
		computed: {
			...mapState({
				list: function(state){
					const user = uni.getStorageSync("user")
					return state.apply.glist.filter(e=>{
						return e.gid == this.id
					})
				}
			})
		},
		methods: {
			goaddfriend:function(){
				uni.navigateTo({
					url:"/pages/friend/addfriend"
				})
			},
			change: async function(e) {
				this.current = e
			},
			applyres: async function(e) {
				console.log(e)
				if(e == 0){
					const ret = await this.$u.put(`friend/friend/agreegapply/${this.currentdata.id}`)
				}
				if(e == 1){
					// 拒绝
					const ret = await this.$u.put(`friend/friend/refusegapply/${this.currentdata.id}`)
				}
			},
			handleApply: async function(e) {
				if(e.status == '申请中'){
					this.show = true
					this.currentdata = e
				}
			},
		}
	}
</script>

<style>
	page {
		background: #fafafa;
	}
</style>

<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		height: 100vh;
		overflow-y: hidden;
	}
</style>